﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Ws.dto
{
    /// <summary>
    /// 封装 用于模拟WS返回数据的的Info节点：请求监控点数据的 返回
    /// </summary>
    public class Response4MonitorBean
    {
    }


    public class ResponseInfo4MonitorData
    {
        [XmlElement(ElementName = "FSUID")]
        public string FSUID { set; get; }

        public ResponseDeviceList4MonitorData DeviceList { set; get; }

        [XmlElement(ElementName = "Result")]
        public string Result { set; get; }

        [XmlElement(ElementName = "Values")]
        public ResponseValues4Request Values { set; get; }

        [XmlElement(ElementName = "FailureCause")]
        public string FailureCause { set; get; }

        public ResponseInfo4MonitorData() { }

    }


    public class ResponseValues4Request
    {
        [XmlElement(ElementName = "DeviceList")]
        public ResponseDeviceList4MonitorData DeviceList { set; get; }

        public ResponseValues4Request() { }

    }

    public class ResponseDeviceList4MonitorData
    {
        [XmlElement(ElementName = "Device")]
        public List<ResponseDevice4MonitorData> Device { set; get; }
         
        public ResponseDeviceList4MonitorData() { }

    }

    public class ResponseDevice4MonitorData
    {
        [XmlAttribute(AttributeName = "ID")]
        public string IDAttribute { set; get; }

        [XmlElement(ElementName = "TSemaphore")]
        public List<TSemaphore4MonitorData> TSemaphore { set; get; }

        public ResponseDevice4MonitorData() { }

        public override string? ToString()
        {
            var sb = new StringBuilder();
            foreach (var item in TSemaphore)
            {
                sb.Append(item.ToString());

            }
            return "Id: " + IDAttribute + ",TSemaphore: " + sb.ToString();
        }

    }

    public class TSemaphore4MonitorData : IComparable<TSemaphore4MonitorData>
    {
        /// <summary> 监控系统数据的种类  1 遥控；2 遥调； 3 遥测； 4 遥信；  </summary>
        [XmlAttribute(AttributeName = "Type")]
        public string Type { set; get; }

        /// <summary> 信元ID </summary>
        [XmlAttribute(AttributeName = "ID")]
        public string ID { set; get; }

        /// <summary> 序号 比如：001 </summary>
        [XmlAttribute(AttributeName = "SignalNumber")]
        public string SignalNumber { set; get; }

        /// <summary> 测量值 </summary>
        [XmlAttribute(AttributeName = "MeasuredVal")]
        public string MeasuredVal { set; get; }

        /// <summary> 设置值 </summary>
        [XmlAttribute(AttributeName = "SetupVal")]
        public string SetupVal { set; get; }

        /// <summary> 信号值状态：0 正常数据；1 无效数据 </summary>
        [XmlAttribute(AttributeName = "Status")]
        public string Status { set; get; }

        /// <summary> 时间 </summary>
        [XmlAttribute(AttributeName = "Time")]
        public string Time { set; get; }

        public TSemaphore4MonitorData() { }

        public override string? ToString()
        {
            return "Type: " + Type + ",ID: " + ID + ",SignalNumber: " + SignalNumber + ",MeasuredVal: " +
                MeasuredVal + ",SetupVal: " + SetupVal + ",Status: " + Status + ",Time: " + Time;
        }

        public int CompareTo(TSemaphore4MonitorData? other)
        {
            try
            {
                if (int.Parse(SignalNumber) > int.Parse(other.SignalNumber))
                {
                    return 1;
                }
                else if (int.Parse(SignalNumber) == int.Parse(other.SignalNumber))
                {
                    return 0;
                }
                else
                {
                    return -1;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[TSemaphore4MonitorData]排序失败，异常 = " + e.Message);
                return -1;
            }
        }
    }

}
